package util

import (
	"github.com/go-resty/resty/v2"
	"net/http"
	"time"
)

const (
	BossCookieName = "sso-epctoken"
)

// 将http的cookies转换成map对象
func GetCookieValueByName(cookies []*http.Cookie, cookieName string) string {

	for k, _ := range cookies {
		if cookies[k].Name == cookieName {
			return cookies[k].Value
		}
	}

	return ""
}


func NewHttpClient(timeout time.Duration) *resty.Client {
	client := resty.New()
	client.SetTimeout(timeout)
	return client
}

func NewHttpClientWithCookie(timeout time.Duration, cookie *http.Cookie) *resty.Client {
	client := resty.New()
	client.SetTimeout(timeout).SetCookie(cookie)
	return client
}

func GetCookie(name, value string) *http.Cookie {
	return &http.Cookie{
		Name:       name,
		Value:      value,
	}
}
